package com.terrier.ui.effects
{
	import com.greensock.TweenLite;
	
	import flash.display.DisplayObject;
	
	public class WxRotateEffect extends WxAbstractEffect
	{
		private var _oldRotation:Number;
		private var _rotateFrom:Number;
		private var _rotateTo:Number;
		private var _rotateType:String;
		
		public function WxRotateEffect(rotateFrom:Number, rotateTo:Number, 
									   runTime:Number = 0.3, 
									   rotateType:String = WxEffectType.LINEAR, 
									   target:DisplayObject = null,
									   startEventParams:Object = null,
									   updateEventParams:Object = null,
									   stopEventParams:Object = null)
		{
			super(target, runTime, startEventParams, updateEventParams, stopEventParams);
			
			this._rotateFrom 	= rotateFrom;
			this._rotateTo 		= rotateTo;
			this._rotateType	= rotateType;
		}
		
		protected override function initialize():void
		{
			if(this.target != null)
			{
				this._oldRotation = this.target.rotation;
				this.target.rotation = this._rotateFrom;
			}
		}
		
		public override function start():void
		{
			super.start();
			if(this.target != null)
			{
				TweenLite.to(target, runTime,
					{rotation:_rotateTo, 
						onComplete:stop});
			}
		}

		public function get oldRotation():Number
		{
			return _oldRotation;
		}

		public function get rotateFrom():Number
		{
			return _rotateFrom;
		}

		public function get rotateTo():Number
		{
			return _rotateTo;
		}
		
		public function get rotateType():String
		{
			return this._rotateType;
		}
		
		public override function clone():IWxAbstractEffect
		{
			var newEffect:WxRotateEffect = new WxRotateEffect(
				this.rotateFrom,
				this.rotateTo, 
				this.runTime, 
				this.rotateType, 
				this.target, 
				this.startEventParams,
				this.updateEventParams, 
				this.stopEventParams);
			return newEffect;
		}
	}
}